package LinkedList和HashSet和HashMap.work03;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

public class Student {
    private String name;
    private int age;
    private float score;

    public Student() {
    }

    public Student(String name, int age, float score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public float getScore() {
        return score;
    }

    public void setScore(float score) {
        this.score = score;
    }

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(0,new Student("张三",20,90.0F));
        list.add(1,new Student("李四",22,90.0F));
        list.add(2,new Student("王五",20,95.0F));
        list.add(3,new Student("赵六",22,100.0F));
        list.add(4,new Student("田七",26,87.0F));
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1,Student o2){
               int result = (int) (o2.getScore() - o1.getScore());
               if (result == 0){
                   result = o1.getAge() - o2.getAge();
               }
               return result;
            }
        });
        System.out.println("姓名\t年龄\t分数");
        for (Student student : list){
            System.out.println(student.getName() + "\t" + student.getAge() + "\t" + student.getScore());
        }
    }
}
